/**
 * Created by Eoly on 2017/1/1.
 */
function Obj() {
    this.objs = []


}
Obj.prototype = {
    checkStrike: function () {
        for (var w in this.objs) {
            if (this.objs[w].isDeath) {
                this.objs.splice(w, 1)
            }
        }
        for (var i = 0; i < this.objs.length; i++) {
            for (var o = 0; o < i; o++) {
                if (this.objs[i] != this.objs[o] && this.objs[i].playerBelongs.id != this.objs[o].playerBelongs.id && !this.objs[i].isDeath && !this.objs[o].isDeath) {
                    var p1 = this.objs[i].centrePoint;
                    var p2 = this.objs[o].centrePoint;
                    var distance = p1.getDistanceFromAnotherPoint(p2);
                    if (distance <= this.objs[i].modelUsed.radius + this.objs[o].modelUsed.radius) {
                        if ((this.objs[i].playerBelongs.id == 10 || this.objs[o].playerBelongs.id == 10) && this.objs[i].playerBelongs.id != this.objs[o].playerBelongs.id) {
                            var givingPack;
                            var plane;
                            if (this.objs[i].playerBelongs.id == 10 && this.objs[o] instanceof Plane && this.objs[o].playerBelongs.id == 0) {

                                givingPack = this.objs[i];
                                plane = this.objs[o];

                                if (givingPack.MainPack != null) {
                                    plane.changeMainWeaponPack(givingPack.MainPack);
                                }
                                if (givingPack.SecondaryPack != null) {
                                    plane.changeSecondaryWeaponPack(givingPack.SecondaryPack);
                                }

                                givingPack.beInjured(99999);
                                plane.beInjured(givingPack.collisionDamage);

                            } else if (this.objs[o].playerBelongs.id == 10 && this.objs[i] instanceof Plane && this.objs[o].playerBelongs.id == 0) {
                                console.log(this.objs[i]);
                                givingPack = this.objs[o];
                                plane = this.objs[i];

                                if (givingPack.mainWeaponPack != null) {
                                    plane.changeMainWeaponPack(givingPack.mainWeaponPack);
                                }
                                if (givingPack.secondaryWeaponPack != null) {
                                    plane.changeSecondaryWeaponPack(givingPack.secondaryWeaponPack);
                                }

                                givingPack.beInjured(99999);
                                plane.beInjured(givingPack.collisionDamage);
                            }
                        }else {
                            //造成伤害
                            this.objs[i].beInjured(this.objs[o].collisionDamage);
                            this.objs[o].beInjured(this.objs[i].collisionDamage);
                        }

                    }
                } else if (this.objs[o].isDeath) {
                }
            }
        }
    }
};